module executor.notice.NoticeExecutor;

import msgtrans;
import message.Constants;
import cache.UserStatusManager;
import hunt.logging;
import google.protobuf;
import message.MsgDefine;
import cache.ChatIdMap;
import client.GateServerClient;
import client.LogicServerClient;
import std.array;
import std.conv : to;

/**
 * 未使用
 */
@TransportClient(LogicClientName)
class NoticeExecutor : AbstractExecutor!(NoticeExecutor) {

  @MessageId(MESSAGE.CMD_NOTIFY_TRANSFER)
  void notice(TransportContext ctx, MessageBuffer buffer)
  {
    Notification notice = new Notification;
    buffer.data.fromProtobuf!Notification(notice);
    logInfof("Notification %d",notice.type);
    if (UserStatusManager.getInstance().getUserStatus(notice.destination))
    {
      TransportSession[ulong] contexts = GateServerClient.getInstance.getAllClient();
      foreach(TransportSession c ; contexts)
      {
        c.send(new MessageBuffer(MESSAGE.CMD_NOTIFY_TRANSFER,notice.toProtobuf.array));
      }
    }
    else
    {
      MessageTransportClient logicClient = LogicServerClient.getInstance().getForwardClient();
      logicClient.send(new MessageBuffer(MESSAGE.CMD_PUT_UNNOTICE,notice.toProtobuf.array));
    }

  }
}

